/*     */ package com.feeyin.radar.sys.controller;
/*     */ 
/*     */ import com.feeyin.radar.commons.DatePropertyEditor;
/*     */ import com.feeyin.radar.commons.Page;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.sys.model.Users;
/*     */ import com.feeyin.radar.sys.service.DepartmentService;
/*     */ import com.feeyin.radar.sys.service.RoleService;
/*     */ import com.feeyin.radar.sys.service.UserService;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.springframework.web.bind.ServletRequestDataBinder;
/*     */ import org.springframework.web.servlet.ModelAndView;
/*     */ import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
/*     */ import org.springframework.web.servlet.view.RedirectView;
/*     */ 
/*     */ public class UserController extends MultiActionController
/*     */ {
/*     */   private UserService userService;
/*     */   private RoleService roleService;
/*     */   private DepartmentService departmentService;
/*     */   private String userManage;
/*     */   private String userList;
/*     */   private String addUser;
/*     */   private String updateUser;
/*     */   private String viewUser;
/*     */ 
/*     */   public UserService getUserService()
/*     */   {
/*  47 */     return this.userService;
/*     */   }
/*     */ 
/*     */   public void setUserService(UserService userService) {
/*  51 */     this.userService = userService;
/*     */   }
/*     */ 
/*     */   public RoleService getRoleService() {
/*  55 */     return this.roleService;
/*     */   }
/*     */ 
/*     */   public void setRoleService(RoleService roleService) {
/*  59 */     this.roleService = roleService;
/*     */   }
/*     */ 
/*     */   public DepartmentService getDepartmentService() {
/*  63 */     return this.departmentService;
/*     */   }
/*     */ 
/*     */   public void setDepartmentService(DepartmentService departmentService) {
/*  67 */     this.departmentService = departmentService;
/*     */   }
/*     */ 
/*     */   public String getUserManage() {
/*  71 */     return this.userManage;
/*     */   }
/*     */ 
/*     */   public void setUserManage(String userManage) {
/*  75 */     this.userManage = userManage;
/*     */   }
/*     */ 
/*     */   public String getUserList() {
/*  79 */     return this.userList;
/*     */   }
/*     */ 
/*     */   public void setUserList(String userList) {
/*  83 */     this.userList = userList;
/*     */   }
/*     */ 
/*     */   public String getAddUser() {
/*  87 */     return this.addUser;
/*     */   }
/*     */ 
/*     */   public void setAddUser(String addUser) {
/*  91 */     this.addUser = addUser;
/*     */   }
/*     */ 
/*     */   public String getUpdateUser() {
/*  95 */     return this.updateUser;
/*     */   }
/*     */ 
/*     */   public void setUpdateUser(String updateUser) {
/*  99 */     this.updateUser = updateUser;
/*     */   }
/*     */ 
/*     */   public String getViewUser() {
/* 103 */     return this.viewUser;
/*     */   }
/*     */ 
/*     */   public void setViewUser(String viewUser) {
/* 107 */     this.viewUser = viewUser;
/*     */   }
/*     */ 
/*     */   public ModelAndView display(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 112 */     Map map = new HashMap();
/* 113 */     map.put("result", request.getParameter("result"));
/* 114 */     map.put("departments", this.departmentService.getDepartments());
/*     */ 
/* 116 */     return new ModelAndView(getUserManage(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView userList(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 121 */     String deptId = request.getParameter("deptId");
/* 122 */     String isActivity = request.getParameter("isActivity");
/*     */ 
/* 124 */     Map map = new HashMap();
/* 125 */     map.put("stopResult", request.getAttribute("stopResult"));
/* 126 */     map.put("deptId", deptId);
/* 127 */     map.put("isActivity", isActivity);
/*     */ 
/* 129 */     if ((!StringUtils.isEmpty(deptId)) && 
/* 130 */       (!StringUtils.isEmpty(isActivity))) {
/* 131 */       Page page = new Page();
/* 132 */       page.getPageList(this.userService.getPageUsersCountByDeptIds(Integer.valueOf(Integer.parseInt(deptId)), isActivity).intValue(), null, request);
/*     */ 
/* 134 */       List users = new ArrayList();
/* 135 */       users = this.userService.getPageUsersByDeptIds(Integer.valueOf(Integer.parseInt(deptId)), isActivity, page);
/* 136 */       map.put("users", users);
/*     */     }
/*     */ 
/* 139 */     return new ModelAndView(getUserList(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView viewUser(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 144 */     Map map = new HashMap();
/*     */ 
/* 146 */     String id = request.getParameter("id");
/* 147 */     if (!StringUtils.isEmpty(id)) {
/* 148 */       map.put("user", this.userService.getUser(Integer.valueOf(Integer.parseInt(id))));
/*     */     }
/* 150 */     return new ModelAndView(getViewUser(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView preAddUser(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 155 */     Map map = new HashMap();
/* 156 */     map.put("result", request.getParameter("result"));
/* 157 */     map.put("repeat", request.getAttribute("repeat"));
/*     */ 
/* 159 */     map.put("depts", this.departmentService.getDepartments());
/* 160 */     map.put("roles", this.roleService.getRoles());
/*     */ 
/* 162 */     return new ModelAndView(getAddUser(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView addUser(HttpServletRequest request, HttpServletResponse response, Users user)
/*     */   {
/* 167 */     boolean result = false;
/* 168 */     int success = 0;
/*     */ 
/* 170 */     if (user != null) {
/* 171 */       if (this.userService.getUserByUserCode(user.getUserCode()) != null) {
/* 172 */         request.setAttribute("repeat", Integer.valueOf(1));
/* 173 */         request.setAttribute("user", user);
/* 174 */         return preAddUser(request, response);
/* 175 */       }if (this.userService.getUserByUserName(user.getUserName()) != null) {
/* 176 */         request.setAttribute("repeat", Integer.valueOf(2));
/* 177 */         request.setAttribute("user", user);
/* 178 */         return preAddUser(request, response);
/*     */       }
/*     */ 
/* 181 */       result = this.userService.insertUser(user);
/* 182 */       if (result) success = 1;
/*     */     }
/*     */ 
/* 185 */     return new ModelAndView(new RedirectView("./user.do?action=preAddUser&result=" + success));
/*     */   }
/*     */ 
/*     */   public ModelAndView preUpdateUser(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 190 */     Map map = new HashMap();
/*     */ 
/* 192 */     map.put("repeat", request.getAttribute("repeat"));
/*     */ 
/* 194 */     map.put("depts", this.departmentService.getDepartments());
/* 195 */     map.put("roles", this.roleService.getRoles());
/*     */ 
/* 197 */     String id = request.getParameter("id");
/* 198 */     if (!StringUtils.isEmpty(id)) {
/* 199 */       map.put("user", this.userService.getUser(Integer.valueOf(Integer.parseInt(id))));
/*     */     }
/* 201 */     return new ModelAndView(getUpdateUser(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView updateUser(HttpServletRequest request, HttpServletResponse response, Users user)
/*     */   {
/* 206 */     boolean result = false;
/* 207 */     int success = 0;
/*     */ 
/* 210 */     if (user != null)
/*     */     {
/* 212 */       if (this.userService.isRepeatUpdateUserCode(user)) {
/* 213 */         request.setAttribute("repeat", Integer.valueOf(1));
/* 214 */         request.setAttribute("user", user);
/* 215 */         return preUpdateUser(request, response);
/* 216 */       }if (this.userService.isRepeatUpdateUserName(user)) {
/* 217 */         request.setAttribute("repeat", Integer.valueOf(2));
/* 218 */         request.setAttribute("user", user);
/* 219 */         return preUpdateUser(request, response);
/*     */       }
/*     */ 
/* 222 */       result = this.userService.updateUser(user);
/* 223 */       if (result) success = 1;
/*     */     }
/*     */ 
/* 226 */     return new ModelAndView(new RedirectView("./user.do?action=display&result=" + success));
/*     */   }
/*     */ 
/*     */   public ModelAndView stopUsers(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 231 */     boolean result = false;
/* 232 */     int success = 0;
/*     */ 
/* 234 */     String[] ids = request.getParameterValues("id");
/* 235 */     if ((ids != null) && (ids.length > 0)) {
/* 236 */       result = this.userService.stopUsers(ids);
/* 237 */       if (result) success = 1;
/* 238 */       request.setAttribute("stopResult", Integer.valueOf(success));
/*     */     }
/* 240 */     return userList(request, response);
/*     */   }
/*     */ 
/*     */   public ModelAndView deleteUsers(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 245 */     boolean result = false;
/* 246 */     int success = 0;
/*     */ 
/* 248 */     String[] ids = request.getParameterValues("id");
/* 249 */     if ((ids != null) && (ids.length > 0)) {
/* 250 */       result = this.userService.deleteUsers(ids);
/* 251 */       if (result) success = 1;
/* 252 */       request.setAttribute("deleteResult", Integer.valueOf(success));
/*     */     }
/* 254 */     return userList(request, response);
/*     */   }
/*     */ 
/*     */   protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
/*     */     throws Exception
/*     */   {
/* 279 */     binder.registerCustomEditor(Date.class, new DatePropertyEditor());
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.controller.UserController
 * JD-Core Version:    0.6.0
 */